package com.xbongbong.saas.enums.business;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.ScreenTypeEnum;
import com.xbongbong.saas.enums.SetTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.base.PaymentBaseEnum;
import lombok.Getter;

/**
 * 经销商应收款枚举
 *
 * @author zcp
 */
@Getter
public enum PaymentDistributorEnum {
    // 应收款模板设置界面展示字段
    // other_1：基本信息
    BASE_INFO(PaymentBaseEnum.BASE_INFO.getAttr(), "enum.paymentDistributor.attrName.base_info", "baseInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 10000, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // serialNo：应收款编号
    PAYMENT_NO(PaymentBaseEnum.PAYMENT_NO.getAttr(), "enum.paymentDistributor.attrName.payment_no", "paymentNo", FieldTypeEnum.SERIALNO.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9990, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // text_4：关联经销商
    DISTRIBUTOR(PaymentBaseEnum.CUSTOMER.getAttr(), "enum.paymentDistributor.attrName.distributor", "distributor", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9980, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // text_5：关联订货单
    ORDER(PaymentBaseEnum.CONTRACT.getAttr(), "enum.paymentDistributor.attrName.order", "order", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9970, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // num_1：应收金额
    AMOUNT(PaymentBaseEnum.AMOUNT.getAttr(), "enum.paymentDistributor.attrName.amount", "amount", FieldTypeEnum.NUM.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9960, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // num_2：实收金额
    REAL_AMOUNT(PaymentBaseEnum.REAL_AMOUNT.getAttr(), "enum.paymentDistributor.attrName.real_amount", "realAmount", FieldTypeEnum.NUM.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9950, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // num_3：未收金额
    UN_AMOUNT(PaymentBaseEnum.UN_AMOUNT.getAttr(), "enum.paymentDistributor.attrName.un_amount", "unAmount", FieldTypeEnum.NUM.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9940, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // num_8：坏账金额
    BAD_AMOUNT(PaymentBaseEnum.BAD_AMOUNT.getAttr(), "enum.paymentDistributor.attrName.bad_amount", "badAmount", FieldTypeEnum.NUM.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // num_4：开票金额
    INVOICE_AMOUNT(PaymentBaseEnum.INVOICE_AMOUNT.getAttr(), "enum.paymentDistributor.attrName.invoice_amount", "invoiceAmount", FieldTypeEnum.NUM.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9920, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // num_61：红冲应收金额
    RED_AMOUNT(PaymentBaseEnum.RED_AMOUNT.getAttr(), "enum.paymentDistributor.attrName.red_amount", "redAmount", FieldTypeEnum.NUM.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9910, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // text_3：回款状态
    STATUS(PaymentBaseEnum.STATUS.getAttr(), "enum.paymentDistributor.attrName.status", "status", FieldTypeEnum.COMBO.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9900, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    // text_6：回款类型
    PAYMENT_TYPE(PaymentBaseEnum.PAYMENT_TYPE.getAttr(), "enum.paymentDistributor.attrName.payment_type", "paymentType", FieldTypeEnum.COMBO.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9890, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // date_20：应收生成日期
    GENERATION_DATE(PaymentBaseEnum.GENERATION_DATE.getAttr(),"enum.paymentDistributor.attrName.generation_time","generationDate",FieldTypeEnum.DATETIME.getType(),1,0,0,ShowTypeEnum.ALL.getCode(),9880,1,1,ScreenTypeEnum.SCREEN_GROUP.getType()),
    // text_81：应收账期
    RECEIVABLE_PERIOD(PaymentBaseEnum.RECEIVABLE_PERIOD.getAttr(),"enum.paymentDistributor.attrName.receivable_period","receivablePeriod",FieldTypeEnum.ACCOUNT_PERIOD.getType(),1,0,0,ShowTypeEnum.LIST_DETAIL.getCode(),9870,1,1,ScreenTypeEnum.SCREEN_GROUP.getType()),
    // date_1：预计回款日期
    ESTIMATE_TIME(PaymentBaseEnum.ESTIMATE_TIME.getAttr(), "enum.paymentDistributor.attrName.estimate_time", "estimateTime", FieldTypeEnum.DATETIME.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9860, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // text_82：来源单据的id，比如回款计划或者销项发票的id
    SOURCE(PaymentBaseEnum.SOURCE.getAttr(),"enum.paymentDistributor.attrName.source","source",FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(),1,0,0,ShowTypeEnum.ALL.getCode(),9850,1,0,ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 资金管理改造第一版本
     * 删除"归属人、支付方式"两个字段，暂时不删除，预先保留字段，方便回滚数据，运行一段时间后在进行删除操作
     * @author chenshan
     * @since 2019-10-30 15:42:55
     */
    // text_7：备注
    MEMO(PaymentBaseEnum.MEMO.getAttr(), "enum.paymentDistributor.attrName.memo", "memo", FieldTypeEnum.TEXTAREA.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9840, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // date_2：实际回款日期
    REAL_PAY_TIME(PaymentBaseEnum.REAL_PAY_TIME.getAttr(), "enum.paymentDistributor.attrName.real_pay_time", "realPayTime", FieldTypeEnum.DATETIME.getType(), 1, 1, 1, ShowTypeEnum.LIST_DETAIL.getCode(), 9830, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // other_2：系统信息
    SYSTEM_INFO(PaymentBaseEnum.SYSTEM_INFO.getAttr(), "enum.paymentDistributor.attrName.system_info", "systemInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9820, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // creatorId：创建人
    CREATOR_ID(PaymentBaseEnum.CREATOR_ID.getAttr(), "enum.paymentDistributor.attrName.creator_id", "creatorId", FieldTypeEnum.CREATORID.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9810, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // addTime：创建时间
    ADD_TIME(PaymentBaseEnum.ADD_TIME.getAttr(),"enum.paymentDistributor.attrName.add_time","addTime",FieldTypeEnum.ADDTIME.getType(),1,1,0,ShowTypeEnum.ALL.getCode(),9800,1,0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // updateTime：更新时间
    UPDATE_TIME(PaymentBaseEnum.UPDATE_TIME.getAttr(),"enum.paymentDistributor.attrName.update_time","updateTime",FieldTypeEnum.UPDATETIME.getType(),1,1,0,ShowTypeEnum.ALL.getCode(),9790,1,0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // array_31：逻辑字段，添加应收款
    ADD_PAYMENT(PaymentBaseEnum.ADD_PAYMENT.getAttr(), "enum.paymentDistributor.attrName.add_payment", "addPayment", FieldTypeEnum.LINK_FORM.getType(), 1, 1, 0, ShowTypeEnum.EDIT.getCode(), 9785, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    // ownerId：负责人
    OWNER_ID(PaymentBaseEnum.OWNER_ID.getAttr(), "enum.paymentDistributor.attrName.owner_id", "ownerId", FieldTypeEnum.OWNERID.getType(), 1, 1, 1, ShowTypeEnum.LIST_DETAIL.getCode(), 9780, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // coUserId：协同人
    COUSERID(PaymentBaseEnum.COUSERID.getAttr(), "enum.paymentDistributor.attrName.couser_id", "coUserId", FieldTypeEnum.COUSERID.getType(), 1, 1, 1, ShowTypeEnum.LIST_DETAIL.getCode(), 9770, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    //text_85：下单人 - 经销商端则为 订货单创建人，读取订货单的 订货单创建人（经销商端的人）
    ORDERER(PaymentBaseEnum.ORDERER.getAttr(), "enum.paymentDistributor.attrName.orderer", "orderer", FieldTypeEnum.TEXTAREA.getType(), 1, 1, 0, ShowTypeEnum.LIST_DETAIL.getCode(), 9765, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 原回款计划根据回款单会有红冲回款计划,资金三期 原回款计划变为 应收款,又加入红冲应收款,与原来的红冲回款计划无关
     * @author yuqian
     */
    // num_5：是否是红冲回款
    IS_RED(PaymentBaseEnum.IS_RED.getAttr(), "enum.paymentDistributor.attrName.is_red", "isRed", FieldTypeEnum.COMBO_NUM.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9760, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // num_6：是否有红冲回款
    HAS_RED(PaymentBaseEnum.HAS_RED.getAttr(), "enum.paymentDistributor.attrName.has_red", "hasRed", FieldTypeEnum.COMBO_NUM.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9750, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 一期前存在红冲，和三期的红冲 应收款概念不一样，加上一个标记隔离开
     */
    // num_62：是否是红冲应收款
    RECEIVABLE_IS_RED(PaymentBaseEnum.RECEIVABLE_IS_RED.getAttr(), "enum.paymentDistributor.attrName.receivable_is_red", "receivableIsRed", FieldTypeEnum.COMBO_NUM.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9740, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // num_63：是否有红冲应收款
    RECEIVABLE_HAS_RED(PaymentBaseEnum.RECEIVABLE_HAS_RED.getAttr(), "enum.paymentDistributor.attrName.receivable_has_red", "receivableHasRed", FieldTypeEnum.COMBO_NUM.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9730, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // num_64：关联单据业务类型
    SOURCE_REF_TYPE(PaymentBaseEnum.SOURCE_REF_TYPE.getAttr(), "enum.paymentDistributor.attrName.source_ref_type", "sourceRefType", FieldTypeEnum.NUM.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9720, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // text_8：关联原回款
    ORIGIN_ID(PaymentBaseEnum.ORIGIN_ID.getAttr(), "enum.paymentDistributor.attrName.origin_id", "originId", FieldTypeEnum.TEXT.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9710, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // text_84：关联原始应收
    RECEIVABLES_ORIGIN_ID(PaymentBaseEnum.RECEIVABLES_ORIGIN_ID.getAttr(), "enum.paymentDistributor.attrName.receivables_origin_id", "receivablesOriginId", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9700, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // text_2：币种
    UNIT(PaymentBaseEnum.UNIT.getAttr(), "enum.paymentDistributor.attrName.unit", "unit", FieldTypeEnum.TEXT.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9690, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // text_10：关联经销商隐藏
    DISTRIBUTOR_LINK_TEXT(PaymentBaseEnum.CUSTOMER_LINK_TEXT.getAttr(), "enum.paymentDistributor.attrName.distributor_link_text", "distributorLinkText", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9680, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    // text_11：关联订货单隐藏
    ORDER_LINK_TEXT(PaymentBaseEnum.CONTRACT_LINK_TEXT.getAttr(), "enum.paymentDistributor.attrName.order_link_text", "orderLinkText", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9670, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    // text_63：关联原始应收隐藏
    RECEIVABLES_ORIGIN_LINK_TEXT(PaymentBaseEnum.RECEIVABLES_ORIGIN_LINK_TEXT.getAttr(),"enum.paymentDistributor.attrName.receivables_origin_link_text","receivablesOriginLinkText",FieldTypeEnum.TEXT.getType(),1,0,1,ShowTypeEnum.NONE.getCode(),9660,1,1,ScreenTypeEnum.SCREEN_OFF.getType()),
    // text_83：关联来源单据隐藏
    SOURCE_LINK_TEXT(PaymentBaseEnum.SOURCE_LINK_TEXT.getAttr(), "enum.paymentDistributor.attrName.source_link_text","sourceLinkTest",FieldTypeEnum.TEXT.getType(),1,0,1,ShowTypeEnum.NONE.getCode(),9650,1,1,ScreenTypeEnum.SCREEN_OFF.getType()),
    //long_1：付款人id 代客操作时为空
    ORDERER_ID(PaymentBaseEnum.ORDERER_ID.getAttr(), "enum.paymentSheetDistributor.attrName.orderer_id", "ordererId", FieldTypeEnum.LONG.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9640, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),

    ;

    /**
     * 英文名称
     */
    private String attr;
    /**
     * 中文名称
     */
    private String attrName;
    /**
     * 对应saas中的attr
     */
    private String saasAttr;
    /**
     * 字段类型，详见
     *
     * @see FieldTypeEnum
     */
    private Integer fieldType;
    /**
     * 重命名、判重、启用必填等权限
     * 1.重命名+字段权限
     * 2.重命名+字段权限+查重
     * 3.重命名+字段权限+启用、必填
     * 4.重命名+字段权限+查重+启用、必填
     * 注：pro中启用和必填是同一个权限，同时启用或同时关闭
     */
    private Integer setType;
    /**
     * 模板设计阶段字段是否允许编辑
     * 1：允许编辑
     * 0：不允许编辑
     */
    private Integer designEditable;
    /**
     * 字段是否显示在模板设计界面
     * 1：不显示
     * 0：显示
     */
    private Integer editHide;
    /**
     * 字段在各个界面（新建、编辑、列表、详情）的展现形式
     * 详见
     *
     * @see ShowTypeEnum
     */
    private Integer showType;
    /**
     * 字段在模板设计界面的排序
     * 建议不要用连续的数字，可以用等差数列，以防以后在两个字段之间加入新字段
     */
    private Integer sort;
    /**
     * 字段在各个界面是否可见(启用)
     * 1：可见
     * 0：不可见
     * 注：字段在具体页面的可见性需要用属性和showType联合判断，在visible=1的情况下判断showType
     */
    private Integer visible;
    /**
     * 字段是否必填
     * 1：必填
     * 0：不必填
     */
    private Integer required;

    /**
     * 筛选类型
     * 1：可筛选
     * 2：不可筛选
     */
    private Integer screenType;

    PaymentDistributorEnum(String attr, String attrName, String saasAttr, Integer fieldType, Integer setType, Integer designEditable,
                           Integer editHide, Integer showType, Integer sort, Integer visible, Integer required, Integer screenType) {
        this.attr = attr;
        this.attrName = attrName;
        this.saasAttr = saasAttr;
        this.fieldType = fieldType;
        this.setType = setType;
        this.designEditable = designEditable;
        this.editHide = editHide;
        this.showType = showType;
        this.sort = sort;
        this.visible = visible;
        this.required = required;
        this.screenType = screenType;
    }

    /**
     * 对data内的字段拼上“data.”
     * @param cache
     * @return java.lang.String
     * @author zcp
     * @date 2019/3/1 18:12
     * @since v1.0
     * @version v1.0
     */
    public static String getAttrConnectData(PaymentDistributorEnum cache) {
        return "data." + cache.getAttr();
    }
    /**
     * 获取es查询、聚合字段
     * data在库内是json对象，对data字段内某个key做es【精确查询】时，需要在其前拼上“data.”，且【text等类型的】要在后面拼“.keyword”
     * @param cache 当前枚举对象
     * @return java.lang.String 处理后的聚合字段
     * @author zcp
     * @date 2019/2/21 14:59
     * @since v1.0
     * @version v1.0
     */
    public static String getEsAttr4Keyword(PaymentDistributorEnum cache) {
        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(cache.fieldType);
        //字段类型为text，或者字段在es内的类型时text，则需要在后面拼上“.keyword”
        boolean flag = fieldTypeEnum == FieldTypeEnum.TEXT || "text".equals(fieldTypeEnum.getEsalias());
        if (flag) {
            return "data." + cache.getAttr() + ".keyword";
        }
        return "data." + cache.getAttr();
    }

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    public static String getI18nValue(String value) {
        return I18nMessageUtil.getMessage(value);
    }
}
